﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Windows;
using PhoneCore.Framework;
using PhoneCore.Framework.Configuration;
using PhoneCore.Framework.IoC;
using PhoneCore.Framework.Views.Command;
using SecureBox.Tools;

using Property = SecureBox.UI.Infrastructure.Model.Property;

namespace SecureBox.UI.ViewModel
{
    public class EmailViewPageModel : TemplateViewPage
    {
        public EmailViewPageModel()
        {
            PasswordActionIconTappedCommand = new ExecuteCommand(OnGeneratePassword);
        }

        #region Methods

        /// <summary>
        /// Sets new password to Password input
        /// </summary>
        private void OnGeneratePassword()
        {
            //TODO extend implementation
            Password = PasswordGenerator.Generate();
            RaisePropertyChanged("Password");
        }

      
        #endregion


        #region  Binding properties

        public string Email { get; set; }
        public string Password { get; set; }

        #endregion


        #region Command properties

        public ExecuteCommand PasswordActionIconTappedCommand
        {
            get;
            private set;
        }

        #endregion


        protected override IEnumerable<Property> GetProperties()
        {
            return new[]
            {
                 new Property() {Name = "Password", Value = Password},
                 new Property() {Name = "Email", Value = Email}
            };
        }

        protected override string GetTemplateName()
        {
            return "Email";
        }

        protected override bool IsValid()
        {
            return base.IsValid();
        }

        protected override void FillProperties()
        {
            Name = EditRecord.Name;
            Keyword = GetKeywordsField();
            Password = GetPropertyValueByName("Password");
            Email = GetPropertyValueByName("Email");
        }

        protected override void EraseProperties()
        {
            Name = string.Empty;
            Keyword = string.Empty;
            Password = string.Empty;
            Email = string.Empty;
        }

    }
}
